#pragma once
#include <iostream>
#include <cstring.h>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "Log.hpp"

using namespace LogModule;

const int default = -1;

class UdpServe
{
public:
    UdpServe(const std::string & ip, uint16_t port)//创建时，接收ip和端口，
        :_socket(-1)
        ,_ip(ip)
        ,_port(port)
    {

    }

    void Init()
    {
        //1.创建套接字
        _socket = socket(AF_INET,SOCK_DGRAM,0);
        if(_socket < 0)
        {
            LOG(LogLevel::FATAL) << "socket error";
            exit(1);
        }
        //2 绑定socket信息，ip 和 端口
        //2.1 填充 sockadd_in结构体
        strcut sockaddr_in local;
        bzero(&local,sizeof(local));
        local.sin_family = AF_INET;
        local.sin_port = htons(_port);
        
    }

    void start()
    {

    }

    ~UdpServe()
    {
        
    }
private:
    int _socket;
    uint16_t _port;
    std::string _ip;
};